//
//  PermanceAgentTopVM.swift
//  kxf
//
//  Created by Mac on 2024/3/27.
//

import Foundation
import UIKit

class PermanceAgentTopVM: UIView {
    
    let selfHeight = kFitWidth(133)

    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: kFitWidth(1), y: frame.origin.y, width: kFitWidth(373), height: selfHeight))
        self.backgroundColor = .white
        self.isUserInteractionEnabled = true
        self.layer.cornerRadius = kFitWidth(8)
        self.clipsToBounds = true
        
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var iconImgView: UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "performance_cell_avatar")
        
        return img
    }()
    lazy var nameLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 16, weight: .medium)
        lab.adjustsFontSizeToFitWidth = true
        
        return lab
    }()
    lazy var bottomView : UIView = {
        let vi = UIView()
        vi.backgroundColor = WHColorWithAlpha(colorStr: "E4E4E4", alpha: 0.12)
        vi.layer.cornerRadius = kFitWidth(8)
        vi.clipsToBounds = true
        
        return vi
    }()
    lazy var rebateTotalLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rebateTotalLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "总收益"
        
        return lab
    }()
    lazy var lineOneView : UIView = {
        let vi = UIView()
        vi.backgroundColor = WHColorWithAlpha(colorStr: "000000", alpha: 0.1)
        
        return vi
    }()
    
    lazy var tradeTotalLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var tradeTotalLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "交易总金额"
        
        return lab
    }()
    lazy var lineTwoView : UIView = {
        let vi = UIView()
        vi.backgroundColor = WHColorWithAlpha(colorStr: "000000", alpha: 0.1)
        
        return vi
    }()
    lazy var tradeNumLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var tradeNumLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.textAlignment = .center
        lab.text = "交易笔数"
        
        return lab
    }()
}

extension PermanceAgentTopVM{
    func updateUI(dict:NSDictionary) {
        rebateTotalLabel.text = "\(dict["subProfit"]as? Double ?? 0.00)"
        tradeTotalLabel.text = "\(dict["subTradeAmount"]as? Double ?? 0.00)"
        tradeNumLabel.text = "\(dict["tradeCount"]as? Int ?? 0)"
    }
}

extension PermanceAgentTopVM{
    func initUI() {
        addSubview(iconImgView)
        addSubview(nameLabel)
        addSubview(bottomView)
        bottomView.addSubview(rebateTotalLabel)
        bottomView.addSubview(rebateTotalLab)
        bottomView.addSubview(lineOneView)
        bottomView.addSubview(tradeTotalLabel)
        bottomView.addSubview(tradeTotalLab)
        bottomView.addSubview(lineTwoView)
        bottomView.addSubview(tradeNumLabel)
        bottomView.addSubview(tradeNumLab)
        
        setConstrait()
    }
    func setConstrait() {
        iconImgView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(21))
            make.top.equalTo(kFitWidth(13))
            make.width.equalTo(kFitWidth(17))
            make.height.equalTo(kFitWidth(19))
        }
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(46))
            make.top.equalTo(kFitWidth(13))
            make.right.equalTo(kFitWidth(-20))
        }
        bottomView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(13))
            make.top.equalTo(kFitWidth(50))
            make.right.bottom.equalTo(kFitWidth(-13))
        }
        lineOneView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(111))
            make.top.equalTo(kFitWidth(14))
            make.width.equalTo(kFitWidth(1))
            make.height.equalTo(kFitWidth(17))
        }
        rebateTotalLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(8))
            make.width.equalTo(kFitWidth(90))
            make.top.equalTo(kFitWidth(4))
        }
        rebateTotalLab.snp.makeConstraints { make in
            make.left.width.equalTo(rebateTotalLabel)
            make.top.equalTo(rebateTotalLabel.snp.bottom).offset(kFitWidth(2))
        }
        tradeTotalLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(133))
            make.width.equalTo(kFitWidth(90))
            make.centerY.lessThanOrEqualTo(rebateTotalLabel)
        }
        tradeTotalLab.snp.makeConstraints { make in
            make.left.width.equalTo(tradeTotalLabel)
            make.centerY.lessThanOrEqualTo(rebateTotalLab)
        }
        lineTwoView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(235))
            make.width.height.equalTo(lineOneView)
            make.centerY.lessThanOrEqualTo(lineOneView)
        }
        tradeNumLabel.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-9))
            make.width.equalTo(rebateTotalLabel)
            make.centerY.lessThanOrEqualTo(rebateTotalLabel)
        }
        tradeNumLab.snp.makeConstraints { make in
            make.right.equalTo(tradeNumLabel)
            make.width.equalTo(rebateTotalLab)
            make.centerY.lessThanOrEqualTo(rebateTotalLab)
        }
    }
}
